package com.wulis.common.converter;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import ma.glasnost.orika.MappingContext;
import ma.glasnost.orika.converter.BidirectionalConverter;
import ma.glasnost.orika.metadata.Type;

import java.time.LocalDateTime;

/**
 *
 * @author wulibao
 */
public class DateTypeConverter extends BidirectionalConverter<LocalDateTime, String> {

    @Override
    public String convertTo(LocalDateTime source, Type<String> destinationType, MappingContext mappingContext) {
        return LocalDateTimeUtil.formatNormal(source);
    }

    @Override
    public LocalDateTime convertFrom(String source, Type<LocalDateTime> destinationType,
        MappingContext mappingContext) {
        return LocalDateTimeUtil.parse(source, DatePattern.NORM_DATETIME_FORMATTER);
    }

}
